package com.nekonomics
package config

import com.alipay.api.AlipayConfig
import zio.ZLayer

case class AliPayConfigProvider(
  gatewayUrl: String,
  appId: String,
  privateKey: String,
  alipayPublicKey: String,
  notifyUrl: String,
  timeoutExpress: String,
  orderDurationMinutes: Int,
  deliveredDurationMinutes: Int

) {

  def toConfig: AlipayConfig = {
    val config = new AlipayConfig()
    config.setServerUrl(gatewayUrl)
    config.setAppId(appId)
    config.setPrivateKey(privateKey)
    config.setAlipayPublicKey(alipayPublicKey)
    config
  }

}

object  AliPayConfigProvider {
  val live = ZLayer.succeed {

    val domain = "http://55b67b82.r30.cpolar.top"

    AliPayConfigProvider(
      gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
      appId = "2021000148631550",
      privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCA8iDlgOnW//XRQ4XnUju23eeQCDlbYeHhJ4+uAhDGTC1+BV6CaUEZcVhnHhseUS0WOYzeYKx1ji8/+hs36h7B1jr9A6dlegDD+f6y3z7GSCmqxRsoSvDK1bu7EKRTBqaL6G13r+iqGQK0A6MgGalSv9cWUaNBIAji0ulcj1lBXHbbVh1Ml5ShSAeOu4j4qQEpIfRugW2ooWCAnO6GXEt6JD/yPIROqjoo3GxZ545I1mZthKL+v5HVHF+EiasGJtiFwEJKxvXmQqlnJGrowAfrQ29+JnKi1Z5p2eJHeSv2KP2EWY9jP6OGVm1dRVAIHmJHlJIavVUV/Ln9zDZS7EeJAgMBAAECggEAHoEpZyHoMAS9kpP2yZKardgxP9GyP/wYA7voMbIrZb3/xSBgC1n7HJnD4CEvKSzrDabvvGwCYI0SgIAakE/ClvinW9PRdiA2riYmKwrFPwMzWELo+c9Ax7tofgih10JrhA2oV/g1gogIK63wmVd4xyq7J3yIso9xird6nXsMEnoFrTVHMdVZTkU5otmh1/zGz6iF4B0GDVZrG8lLz4YDgfWFT234e4oYOG8PdNl0QAhosc05UFzJdNDkakOTifxjmstVnmHRgBWDGG/X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b2vhju5VDH35k6WGR4dTXjb/3epuCppkdzWykXwTMPsN9bMQcmnCekxzHCFHXBxlnNjLB9sJvaEBpySVv+KZ+rZAXIFdxcRIhTgYj4eJ4JSAVBII81mT9GOD2hQ5xqOOEY6xEAmwsekpj0R/IbIEND8CZAeV20f24+57XXnG16LP8FLlyeglbaXvcgU2LcEfhLZ7RNC79fpjJx0GZS6E8Q3wAkUIzSBKDZfT1MuvsC5k+5O32IX05R+z78ny6/dWMreoI6zmdJkYAR/k6gcQIDAQAB",
      notifyUrl = s"$domain/api/pay/notify",
      timeoutExpress = "15m",
      orderDurationMinutes = 10,
      deliveredDurationMinutes = 2
    )
  }
  
}

